<?php

namespace App\Admin\Forms;

use App\Models\ActivityAreaSetting;
use App\Models\ActivityInformation;
use App\Models\Contract;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Tree;
use Dcat\Admin\Widgets\Form;

class EntryAreaSetting extends Form implements LazyRenderable
{
    use LazyWidget;

    public function handle(array $input)
    {
        // $input['url'] = config('filesystems.disks.qiniu.domains.https') . $input['url'];
        $resutl = ActivityAreaSetting::updateOrCreate(['act_id' => $input['act_id']], $input);
        if ($resutl) {
            return $this->response()->success('修改成功')->refresh();
        } else {
            return $this->response()->error('修改失败')->refresh();
        }
    }

    public function
    default()
    {

        return [
            // 展示上个页面传递过来的值
            'act_id' => $this->payload['act_id'],
        ];
    }

    public function form()
    {
        $this->hidden('act_id');
        $this->select('parent_id', trans('admin.parent_id'))
            ->options(ActivityAreaSetting::selectOptions())
            ->saving(function ($v) {
                return (int) $v;
            });
        $this->text('title');
        $this->text('order');
        $this->hidden('status')
            // ->customFormat(function ($v) {
            //     return $v == 1 ? 1 : 0;
            // })
            ->saving(function ($v) {
                return $v;
            });
    }
}
